<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="180px">
        <Layout />
      </el-aside>
      <el-container>
        <el-header>
          <Header />
        </el-header>
        <el-main>
          <div class="screen">
            <div class="left">
              <!-- <leftMenu /> -->
            </div>
            <div class="right">
              <div class="up">
                <chatMessage :sendMessage="sendMessage" :data='data' />
              </div>
            </div>

          </div>
          <div class="input-box">
              <el-input class="inputStyle" v-model="message" placeholder="请输入问题" clearable />
              <el-button @click="send" @keyup.enter="keyDown($event)">发送</el-button>
            </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import Header from '@/components/Header/index.vue';
import Layout from '@/components/layout.vue';
import { ref, onMounted } from 'vue'
// import { ElLoading } from 'element-plus'
import chatMessage from './components/chat.vue'

/** 发送消息模块 */
let message = ref('')
let sendMessage = ref('')
let data = ref() // 定义一个时间戳，方便检查是否更新发送了数据
/** 发送消息的方法 */
function send() {
  sendMessage.value = message.value
  data.value = Date.now()
  message.value = ''
  // console.log(data.value);
}

/** 刷新加载 */
onMounted(() => {
  // openFullScreen2();
  window.addEventListener("keydown", keyDown);
});
/** 回车方法 */
function keyDown(e: any) {
  // 回车则执行登录方法 enter键的ASCII是13
  if (e.key == 'Enter') {
    send()
  }
}
/** 加载中... */
// const openFullScreen2 = () => {
//   const loading = ElLoading.service({
//       lock: true,
//       text: '',
//       background: 'rgba(0, 0, 0, 0.7)',
//   })
//   setTimeout(() => {
//       loading.close()
//   }, 2000)
// }
</script>

<style scoped lang="less">
.screen {
  height: 80vh;
  display: flex;
  flex-direction: row;
  background: rgb(236, 239, 246);
}

.right {
  width: 100%;
  position: relative;
}

.up {
  position: absolute;
  top: 10px;
  left: 5px;
  width: 100%;
  /* align-items: center; */
}

.input-box {
  // position: absolute;
  float: right;
  margin-top: 10px;
  // width:100%
  // display: flex;
  // bottom: 10px;
  // width: 80%;
  // left: 30%;
}

.inputStyle {
  width: 300px;
  margin-right: 10px;
}

.common-layout {
  height: 100%;

  .el-container {
    height: 100%;
  }

  .el-header {
    padding: 0;
  }
}
</style>